/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 *
 * @author spthanh
 */
public class InsertingRow_Example {
    public static void main(String[] args){
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks", "sa", "123456");

            String query = " SELECT * FROM Production.Location ";
            Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);

            ResultSet rs = stmt.executeQuery(query);

            //Move cursor to the insert-row
            rs.moveToInsertRow();

            //Set values for insert row
            rs.updateString("Name", "Alex");
            rs.updateBigDecimal(3,new BigDecimal(10.00));
            rs.updateDouble(4, new Double(12.40));

            //Commit append new row in resultSet
            rs.insertRow();

           //Move to the previous row
            rs.moveToCurrentRow();

        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
